
const state = () => ({
  token: null,
  isAuthenticated: false
})

// getters
const getters = {
  token: (state) => {
    return state.token
  },
  isAuthenticated: (state) => {
    return state.isAuthenticated
  }
}
// mutations
const mutations = {
  setToken(state, token) {
    state.token = token
  },
  setIsAuthenticated(state, isAuthenticated) {
    state.isAuthenticated = isAuthenticated
  }
}

// actions
const actions = {
  authenticated({ commit }, token) {
    if (token != null) {
      commit('setToken', token)
      commit('setIsAuthenticated', true)
    }
  },
  logout({ commit }) {
    commit('setToken', null)
    commit('setIsAuthenticated', false)
  }


}

export default createStore(
  {
    namespaced: true,
    state,
    getters,
    actions,
    mutations
  }
)
